package com.ruoyi.peach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peach.domain.Farming;
import com.ruoyi.peach.service.IFarmingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农事Controller
 * 
 * @author ruoyi
 * @date 2025-05-04
 */
@RestController
@RequestMapping("/peach/farming")
public class FarmingController extends BaseController
{
    @Autowired
    private IFarmingService farmingService;

    /**
     * 查询农事列表
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:list')")
    @GetMapping("/list")
    public TableDataInfo list(Farming farming)
    {
        startPage();
        List<Farming> list = farmingService.selectFarmingList(farming);
        return getDataTable(list);
    }
    /**
     * 查询农事列表
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:list')")
    @GetMapping("/list/app")
    public R listApp(Farming farming)
    {

        return R.ok(farmingService.selectFarmingList(farming));

    }

    /**
     * 导出农事列表
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:export')")
    @Log(title = "农事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Farming farming)
    {
        List<Farming> list = farmingService.selectFarmingList(farming);
        ExcelUtil<Farming> util = new ExcelUtil<Farming>(Farming.class);
        util.exportExcel(response, list, "农事数据");
    }

    /**
     * 获取农事详细信息
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(farmingService.selectFarmingById(id));
    }

    /**
     * 新增农事
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:add')")
    @Log(title = "农事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Farming farming)
    {
        return toAjax(farmingService.insertFarming(farming));
    }

    /**
     * 修改农事
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:edit')")
    @Log(title = "农事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Farming farming)
    {
        return toAjax(farmingService.updateFarming(farming));
    }

    /**
     * 删除农事
     */
    @PreAuthorize("@ss.hasPermi('peach:farming:remove')")
    @Log(title = "农事", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(farmingService.deleteFarmingByIds(ids));
    }
}
